<?php
	include("../../include/dbconnect.php");
	
	$table="chungloai";
	session_start();
	header('Content-type: application/json; charset=utf-8');
	if(!isset($_SESSION["un"])) $_SESSION["un"]="";
	if($_SESSION["un"]!="")
	{
		$found=false;
		$rs=mysql_query("select * from $table where ten='".$_POST["ten"]."'",$conn);
		$found=(mysql_num_rows($rs)>0);
		mysql_free_result($rs);
		if($found)
		{
			echo "{\"status\":0,\"id\":\"0\"}";
			die();
		}
		
		$idchungloai=$_POST["id"];
		if($idchungloai=="0") $idchungloai="null";
		mysql_query("insert into $table (ten,idchungloai,un) values ('".$_POST["ten"]."',$idchungloai,'".$_SESSION["un"]."')",$conn);
		$id=mysql_insert_id($conn);
		echo "{\"status\":1,\"id\" : \"$id\"}";
	}
	else echo "{\"status\":0,\"id\" : \"0\"}";
	include("../../include/dbclose.php");
?>
